<template>
    <div>
        <van-nav-bar title="搜索" left-text="返回" left-arrow @click-left="onClickLeft" />

        <van-search v-model="searchvalue" placeholder="请输入搜索关键词" input-align="center" />
        <van-empty image="https://fastly.jsdelivr.net/npm/@vant/assets/custom-empty-image.png" image-size="80"
            description="描述文字" v-if="status" />
        <div v-for="item in searchData" v-else>
            <router-link :to="'/detail/' + item.goods_id">
                <van-card num="2" :price="item.goods_price" :title="item.goods_name"
                    :thumb="item.goods_big_logo ? item.goods_big_logo : 'https://fastly.jsdelivr.net/npm/@vant/assets/ipad.jpeg'" />
            </router-link>
        </div>



    </div>
</template>

<script setup>
import { searchApi } from '@/api/api';
import router from '@/router';
import { ref, watch } from 'vue';
import _ from 'lodash'
const searchvalue = ref('')
let status = ref(true)
const onClickLeft = () => {
    router.push('/')
}
let searchData = ref([])
// goods_name
watch(searchvalue,
 _.debounce(val => {
    searchApi(val).then(res => {
        console.log(res);
        searchData.value = res.data.message.goods
        if (searchData.value == null) {
            status.value = true
        } else {
            status.value =false
        }

    }
)


})
)


</script>

<style lang="scss" scoped></style>